import pandas as pd
from tools import dbTool


def getSplitData():
    df = dbTool.getDF("select * from dt_company_20241223 order by market_value_total asc")
    # 使用qcut将数据分成5个等频的分位数
    df['quantile'] = pd.qcut(df['market_value_total'], 5, labels=False)

    # 统计每个分位数的值
    quantile_stats = df.groupby('quantile')['market_value_total'].agg(['count', 'mean', 'std', 'min', 'max'])
    quantile_stats = quantile_stats.round().astype(int)
    print(quantile_stats)
    """ 结果: 
    quantile    count  mean   std  min    max
    0          1023    21     5    6     28
    1          1023    36     4   28     43
    2          1023    56     8   43     71
    3          1023   104    23   71    154
    4          1023   745  1875  154  22274
    """


if __name__ == '__main__':
    getSplitData()
